﻿using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Security.Principal;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;
using System.Web.Security;
using OrderPortal.Models;
using Runda.CMS.Order.Entity;
using Runda.CMS.Order.Repository;

namespace OrderPortal.Controllers
{
    [RequiresAuthentication]
    public class RequiresAuthenticationAttribute : ActionFilterAttribute
    {
        public override void OnActionExecuting(ActionExecutingContext filterContext)
        { 
            if((Account)filterContext.HttpContext.Session["currentUser"] == null)
            {
                string redirectOnSuccess = filterContext.HttpContext.Request.Url.AbsolutePath;                  
                string redirectUrl =  string.Format("?ReturnUrl={0}",redirectOnSuccess);
                string loginUrl = FormsAuthentication.LoginUrl + redirectUrl;
                filterContext.HttpContext.Response.Redirect(loginUrl, true);
            }
        }
    }
}